const defaults = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
Page({
  data: {
    avatarUrl: wx.getStorageSync('avatarUrl') || defaults, //默认的头像
    nickname: ''
  },
  onLoad() {
    // console.log(1)
  },
  onChooseAvatar(e) {
    console.log(e)
    // wx.setStorageSync('avatarUrl', e.detail.avatarUrl)
    this.setData({
      avatarUrl: e.detail.avatarUrl
    })
  },
  setNickname(e) {
    this.setData({
      nickname: e.detail.value
    })
  },
  onSumit() {
    if (!this.data.nickname.trim()) return wx.showToast({
      title: '请输入昵称',
      icon: 'error'
    })
    if (!wx.getStorageSync('tokens')) {
      wx.navigateTo({
        url: '/pages/logs/logs'
      })
      return wx.showToast({
        title: '请先登录',
        icon: 'error'
      })
    }
    const userInfo = {
      avatarUrl: this.data.avatarUrl,
      nickname: this.data.nickname
    }
    wx.setStorageSync('userInfo', userInfo)
    wx.switchTab({
      url: '/pages/my/my',
    })
    wx.showToast({
      title: '提交成功',
      icon: 'success'
    })
  }
})